﻿using System.Linq;
using Abp.Authorization;
using Abp.Localization;
using LeadThing.AbpZeroTemplate.Authorization;


namespace LeadThing.AbpZeroTemplate.WorkFlows.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="WorkFlowAppPermissions"/> for all permission names.
    /// </summary>
    public class WorkFlowAppAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            //在这里配置了WorkFlow 的权限。

            var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));

            var entityNameModel = pages.Children.FirstOrDefault(p => p.Name == AppPermissions.Pages_WorkFlow)
              ?? pages.CreateChildPermission(AppPermissions.Pages_WorkFlow, L("Pages_WorkFlow"));





            var workFlow = entityNameModel.CreateChildPermission(WorkFlowAppPermissions.WorkFlow, L("WorkFlow"));
            workFlow.CreateChildPermission(WorkFlowAppPermissions.WorkFlow_CreateWorkFlow, L("CreateWorkFlow"));
            workFlow.CreateChildPermission(WorkFlowAppPermissions.WorkFlow_EditWorkFlow, L("EditWorkFlow"));
            workFlow.CreateChildPermission(WorkFlowAppPermissions.WorkFlow_DeleteWorkFlow, L("DeleteWorkFlow"));

        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, AbpZeroTemplateConsts.LocalizationSourceName);
        }
    }

}